package com.wdy.golden.tinysql.util;

import com.wdy.golden.tinysql.constant.TinysqlConstants;

/**  
 * @author Dongye_Wu
 * @version: 1.0.0
 * @Description: TODO
 * @date 2020年4月16日 下午11:03:52 
 */
public class TinysqlUtil {
	public static final String likeStr = "%";
	
	public static String leftLike(String value) {
		return value + likeStr;
	}
	
	public static String rightLike(String value) {
		return likeStr + value;
	}
	
	public static String bothLike(String value) {
		return likeStr + value + likeStr;
	}
	
	public static String getPaginationSql(String sql, int rowEnd, int rowStart) {
		StringBuffer scriptSb = new StringBuffer(sql);
		scriptSb.insert(0, TinysqlConstants.PAGINATION_PREFIX);
		scriptSb.append(String.format(TinysqlConstants.PAGINATION_SUFFIX, rowStart, rowEnd));
		return scriptSb.toString();
	}
	
	public static String getCountSql(String sql) {
		StringBuffer scriptSb = new StringBuffer(sql);
		scriptSb.insert(0, TinysqlConstants.COUNT_PREFIX);
		scriptSb.append(String.format(TinysqlConstants.COUNT_SUFFIX));
		return scriptSb.toString();
	}
}
